export default {
  name: "employment",
  components: {
    cityCascader: () => import("../../component/cityCascader/index.vue"),
    check: () => import("../socical/socialCheck/check.vue")
  },
  data() {
    return {
      form: {
        companyname: "",
        province: "",
        city: "",
        area: "",
        citys: [],
        companytype: "",
        companysize: "",
        pagenum: 1,
        pagesize: 10
      },
      level: '0',
      total: 0,
      list: [],
      typeList: [],
      sizeList: [],
      checkFlag: false,
      info: "",
    };
  },
  mounted() {
    this.getType();
    this.getSize();
    this.getTableData();
    this.getAuthority();
  },
  methods: {
    getAuthority() {
      let userinfo = localStorage.getItem('userinfo');
      userinfo = JSON.parse(userinfo);
      this.level = userinfo.level;
      this.form.province = +userinfo.province || '';
      this.form.city = +userinfo.city || '';
      this.form.area = +userinfo.area || '';
      this.form.citys = [];
      this.form.citys.push(+userinfo.province);
      this.form.citys.push(+userinfo.city);
      this.form.citys.push(+userinfo.area);
    },
    // 获取企业类型
    getType() {
      this.$axios
        .post("/system/v1/common/dict", {
          groupid: "companytype"
        })
        .then(res => {
          if (res.data.message === "success.") {
            this.typeList = res.data.data;
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
    },
    // 获取企业规模
    getSize() {
      this.$axios
        .post("/system/v1/common/dict", {
          groupid: "companysize"
        })
        .then(res => {
          if (res.data.message === "success.") {
            this.sizeList = res.data.data;
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
    },
    // 获取列表数据
    getTableData() {
      this.$axios.post("/app/v1/platform/company/employList", this.form).then(res => {
          if (res.data.code === 1) {
            let result = res.data.data;
            this.list = result.list;
            this.total = Number(result.totalnum);
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
    },
    handleCityChange(val) {
      this.form.citys = val;
      this.form.province = val[0];
      this.form.city = val[1];
      this.form.area = val[2];
    },
    // 搜索
    search() {
      this.form.pagenum = 1;
      this.getTableData();
    },
    // 重置
    reset() {
      this.$refs["empform"].resetFields();
      this.form.pagenum = 1;
      this.getAuthority();
    },
    linkTo(row, name, params) {
      if (!params) {
        this.$router.push({
          name,
          params: {
            companyid: row.companyid
          }
        })
      } else {
        this.$router.push({
          name,
          params: {
            companyid: row.companyid,
            params
          }
        })
      }
    },
    checkInfo(r) {
      this.checkFlag = true;
      this.info = r;
    },
    // 分页
    handleCurrentChange(val) {
      this.form.pagenum = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.form.pagenum = 1;
      this.form.pagesize = val;
      this.getTableData();
    },
  }
};